/**
 * Created by xxx on 2017/3/27.
 */var height = $(document.body).height()+"px";
//用react封装
var currentpage = 1,totlepage = 1,i,pagecount=15,tempCurrentPage = 1;//分页的当前页和总的页数
//表单数据：学校页面的对应注解：学校名称 考勤区域  隶   属地区 设备自定义套餐（扩展）学校id
var simData = [],importSimData = [];
var importSim = {isImportSim:false};//是否导入
var allSimCount = 0; //每个批次下面的设备总量
//表单的最高高度、当前第几页、总页数、总行数、设备投放切换、箱号
var otherData = {maxHeight:'0px',currentpage:0,totlepage:0,totlerows:0,pageLeft:0,pageRight:0,view:'',boxOrdevice:'device',batchNumber:'',upBatchNumber:''};
var Page = React.createClass({
    render: function () {
        {
            var items = [],
                svar = this;
            if(otherData.totlepage == 0 ){
                items.push({num:1,checked:true})
            }else if(totlepage < 6){
                for(i = 1;i <= totlepage ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage >= (totlepage-2)) {//点在左边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                for(i = totlepage-2;i <= totlepage ;i++){
                    if(i == currentpage){
                        items.push({num:i,checked:true})
                    }else{
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage <= 3){
                for(i = 1;i <= 3 ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }else {//点在两边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:currentpage-1,checked:false});
                items.push({num:currentpage,checked:true});
                items.push({num:currentpage+1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }
        }
        return (
            <div className="tableInfo-page">
                <div className="page-number">每页{pagecount}条</div>
                <div className="page-limit">
                    <ol className="page-limit-ol">
                        <ol className="page-limit-ol">
                            <li className="page-limit-img" name="-1" onClick={otherData.pageLeft == 0?'':svar.props.onPageClick.bind(svar,-1)} ><span className={otherData.pageLeft == 0?'page-limit-left-no':'page-limit-left-yes'}/></li>
                            {
                                items.map(function (item) {
                                    return (<li onClick={isNaN(item.num)?'':svar.props.onPageClick.bind(svar,item.num)}  className={item.checked == true?'page-limit-num page-limit-checked':'page-limit-num'} name={item.num}>{item.num}</li>)
                                })
                            }
                            <li className="page-limit-img" name="-2" onClick={otherData.pageRight == 0?'':svar.props.onPageClick.bind(svar,-2)} ><span className={otherData.pageRight == 0?'page-limit-right-no':'page-limit-right-yes'}/></li>
                        </ol>
                    </ol>
                </div>
            </div>
        );
    },
});
//按sim
var SIMTable = React.createClass({
    clickChecked: function () {
        var childsCheckBox = $(".SIMDelivery-body").children();
        var b = 0,a = 0;
        for(var i = 0;i<childsCheckBox.length;i++){
            var child = $($(childsCheckBox[i]).children()[0]).children();
            if($(child[0]).length == 0){
                a ++;
            }
            if($(child[0]).is(':checked')){
                b ++;
            }
        };
        if(b == childsCheckBox.length-a){
            $(".simCheckBox").prop('checked',true);
        }else{
            $('.simCheckBox').attr('checked',false);
        }
    },
    render: function () {
        return (
            <tr>
                <td style={{width: '3%'}}>{this.props.status=='0' || this.props.status=='1'?<input onClick={this.clickChecked} className="simChildCheckBox" data-value={this.props.id} type="checkbox"/>:""}</td>
                <td style={{width: '10%'}}>{this.props.operations}</td>
                <td style={{width: '10%'}}>{this.props.phone}</td>
                <td style={{width: '10%'}}>{this.props.iccid}</td>
                <td style={{width: '10%'}}><span style={{color:this.props.peoplename==null || this.props.peoplename==''?'#FF5959':'#000000'}}>{this.props.peoplename==null || this.props.peoplename==''?'未激活':this.props.peoplename}</span></td>
                <td style={{width: '10%'}}>{this.props.peopleidcard}</td>
                <td style={{width: '10%'}}>{this.props.mdtid}</td>
                <td style={{width: '10%'}}><span style={{color:this.props.status==null ||this.props.status=='0'?'#FF5959':(this.props.status=='1'?'#000000':'#01b4ee')}}>{this.props.status==null ||this.props.status=='0'?'未开机匹配':(this.props.status=='1'?'已使用':'已回收')}</span></td>
            </tr>
        );
    }
});
//导入sim卡
var ImportSIMTable = React.createClass({
    render: function () {
        return (
            <tr>
                <td>{this.props.operations}</td>
                <td>{this.props.phone}</td>
                <td>{this.props.iccid}</td>
                <td>{this.props.createtimestr}</td>
            </tr>
        );
    }
});
var AddSIM = React.createClass({
    //关闭弹出层
    onClickHidePop: function () {
        $(".initializeMenu", window.parent.document).hide();//父页面的遮罩
        $(".addSIM").hide();
        $(".errorMsg").hide();
        $("#sim_iccid").val("")
        $("#sim_phone").val("")
    },
    //保存新增设备
    addSim: function () {
        var svar = this;
        if($("#sim_phone").val()==""){
            $(".phone-error").show();
            return;
        }else if($("#sim_phone").val().length != 11){
            $(".phone-error").show();
            return;
        }
        if($("#sim_iccid").val()==""){
            $(".ICCID-error").show();
            return;
        }else if($("#sim_iccid").val().length != 20){
            $(".ICCID-error").show();
            return;
        }
        var param="param={";
        param = getJsonDataNotEmpty(param,"iccid",$("#sim_iccid").val());
        param = getJsonDataNotEmpty(param,"phone",$("#sim_phone").val());
        param = getJsonDataNotEmpty(param,"operations",$("#sim_operations").val());
        param += "}";
        suixun.showLoding();//显示加载中
        $.ajax({
            url:serverUrl+'/simInfoManage/addSimInfo.json',
            data:param,
            dataType:'json',
            success:function (data) {
                suixun.hideLoding(200);//隐藏加载中
                if(data!=null && data.code == 200){
                    suixun.alert("新增成功",function (data) {
                        if(data){
                            svar.onClickHidePop();
                            svar.props.onPageClick(currentpage);
                        }
                    });
                } else {
                    suixun.alert((data!=null && data.msg!=null)?data.msg:"新增失败");
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });
    },
    //查询箱号
    onClickPhoneQuery: function (e) {
        suixun.alert("查询箱号")
    },
    //验证
    onBlurInput: function (e) {
        var classname = e.target.getAttribute("data-error");
        if($(e.target).val() == ''){
            $("."+classname+"").show();
        }else{
            $("."+classname+"").hide();
        }
    },
    render: function () {
        return (
            <form name="simForm">
                <div  className="pop popPhone addSIM popModel">
                    <div className="model"></div>
                    <div className="pop-info popModel-info addSIM-info">
                        <div className="pop-title popModel-title">
                                        <span className="pop-title-content popModel-title-content addSIM-popModel-title-content">
                                            <span className="pop-title-content-solid-left popModel-title-content-solid-left" />
                                                新增SIM卡
                                            <span className="pop-title-content-solid-right popModel-title-content-solid-right"  />
                                        </span>
                            <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                            <input type="hidden" name="sim_simids" id="sim_simids" />
                        </div>
                        <div className="popModel-body">
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">运营商</span>
                                <span className="popModel-body-input-content" >
                                            <select className="export-factory" id="sim_operations">
                                               <option value="中国移动" selected="selected" >中国移动</option>
                                                <option value="中国电信" >中国电信</option>
                                                <option value="中国联通" >中国联通</option>
                                            </select>
                                        </span>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">手机号码</span>
                                <span className="popModel-body-input-content">
                                     {/*data-error="fee2-error" */}
                                        <input className="input-content " data-error="phone-error" onBlur={this.onBlurInput} id="sim_phone" type="text" placeholder="请输入手机号"  />
                                    </span>
                                <div className="errorMsg phone-error" ></div>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">ICCID</span>
                                <span className="popModel-body-input-content">
                                        {/*data-error="fee2-error" */}
                                        <input className="input-content " data-error="ICCID-error" onBlur={this.onBlurInput} id="sim_iccid" type="text" placeholder="请输入SIM卡ICCID"  />
                                    </span>
                                <div className="errorMsg ICCID-error" ></div>
                            </div>
                        </div>
                        <div className="popModel-button" style={{marginTop:"-25px"}}>
                            <span className="popModel-button-ok" onClick={this.addSim}>确定</span>
                        </div>
                    </div>
                </div>
            </form>
        );
    }
});
//批量导入
var ExcelInput = React.createClass({
    //关闭弹出层
    onClickHidePop: function () {
        $(".initializeMenu", window.parent.document).hide();//父页面的遮罩
        $(".excelInput").hide();
    },
    //选择Excel文件
    onChangFile: function () {
        var fileUrl = $("#file").val().split('\\');//注split可以用字符或字符串分割
        var fileName = fileUrl[fileUrl.length-1];//这就是要取得的图片名称
        var fileLat = fileName.substring( fileName.lastIndexOf('.')+1 );//后缀名称
        if(fileLat == "xls" || fileLat == "xlsx" ){
            $(".file_name").val(fileName);
        }else{
            suixun.alert("请选择Excel文件上传!",function (data) {
                if(data){
                    $(".file_name").val("");
                }
            });
        }
    },
    render: function () {
        return (
            <div  className="pop popPhone excelInput popModel">
                <div className="model"></div>
                <div className="pop-info popModel-info excelInput-info">
                    <div className="pop-title popModel-title ">
                                <span className="pop-title-content popModel-title-content">
                                    <span className="pop-title-content-solid-left popModel-title-content-solid-left" style={{width:"180px "}} />
                                        批量导入
                                    <span className="pop-title-content-solid-right popModel-title-content-solid-right"  style={{width:"180px "}} />
                                </span>
                        <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                    </div>

                    <div className="pop-body popModel-body">
                        <div className="popModel-body-input">
                            <span className="popModel-body-input-title" style={{width: "108px",lineHeight:"41px",backgroundPosition:"106px 0px"}}>选择Excel文件</span>
                            <form name="excelInputForm" id="excelInputFrom"  enctype="multipart/form-data" method="post">
                                <input className="file_name input-content export-imei" type="text" name="filename" readOnly="readOnly"/>
                                <a href="javascript:;" className="file">选择文件
                                    <input type="file" onChange={this.onChangFile}  name="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel " id="file" />
                                </a>
                            </form>
                        </div>


                    </div>
                    <div className="popModel-button" style={{marginTop:"20px"}}>
                        <span className="popModel-button-ok" onClick={this.props.excelInput}>导入</span>
                    </div>
                </div>
            </div>
        );
    }
});
//新增批号弹出层
var Addbatchnumber = React.createClass({
    onClickHidePop: function () {
        $(".initializeMenu", window.parent.document).hide();//父页面的遮罩
        $(".addBatchNumber").hide();
    },
    render: function () {
        return (
            <div  className="pop popPhone addBatchNumber">
                <div className="model"></div>
                <div className="pop-info popPhone-info">
                    <div className="pop-title popPhone-title">
                        <span className="pop-title-content popPhone-title-content">
                            <span className="pop-title-content-solid-left popPhone-title-content-solid-left"/>
                            编辑批号
                            <span className="pop-title-content-solid-right popPhone-title-content-solid-right"/>
                        </span>
                        <span className="pop-title-img popPhone-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        <input type="hidden" name="batch_id" id="batch_id"/>
                    </div>
                    <div className="pop-body">
                        <div className="pop-body-input">
                            <span className="pop-body-input-title">批号名</span>
                            <span className="pop-body-input-content">
                                <input className="input-content " type="text" placeholder="请输入批号" name="batch_batchcode" id="batch_batchcode"/>
                            </span>
                            <span className="verify imei-error" />
                        </div>
                    </div>
                    <div className="pop-button" style={{marginTop:'50px'}}>
                        <span className="pop-button-ok" onClick={this.props.onClockSaveAddbatchnumber}>保存</span>
                    </div>
                </div>
            </div>
        );
    }
})
//SIM卡投放组件
var SIMDelivery = React.createClass({
    onPageClick: function (num) {
        //分页-调用ajac然后把数据查询出来:获取name的值
        //计算currentpage
        suixun.showLoding();//显示加载中
        var onPageLeft = 0,onPageRight = 1;
        if(num > 0){
            currentpage = num;
        }else if(num == -1 && currentpage > 1){
            currentpage --;
        }else if(num == -2  && currentpage < totlepage){
            currentpage ++;
        }
        //修改左右的按钮
        if((currentpage == totlepage && totlepage == 1)|| totlepage == 0){
            onPageLeft = 0;
            onPageRight = 0;
        }else if(currentpage == totlepage && totlepage > 1){
            onPageLeft = 1;
            onPageRight = 0;
        }else if(1 < currentpage && currentpage < totlepage){
            onPageLeft = 1;
            onPageRight = 1;
        }
        //判断是不是导入页面
        if(importSim.isImportSim == true){
            importSimData = [];
            var param="param={";
            param = getJsonDataNotEmpty(param,"pagenumber",""+currentpage+"");
            param = getJsonDataNotEmpty(param,"pagecount",""+pagecount+"");
            param += "}";
            $.ajax({
                url:serverUrl+'/simInfoManage/querySimTmpList.json',
                data:param,
                dataType:'json',
                success:function (data) {
                    suixun.hideLoding();//隐藏加载中
                    if(data.code == 200){
                        if(data.info.queryresult != null){
                            for(var i=0;i<data.info.queryresult.length;i++){
                                var obj=data.info.queryresult[i];
                                importSimData[i] = {id:i,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,createtimestr:obj.createtimestr};
                            }
                        }
                        otherData.totlepage = data.info.totlepage;
                        otherData.totlerows = data.info.totlerows;
                        otherData.pageLeft = onPageLeft;
                        otherData.pageRight = onPageRight;
                        otherData.currentpage = currentpage;
                        totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                        this.setState({importSimData:importSimData,otherData:otherData});
                    }
                }.bind(this),
                error: function (req,info,error) {
                    top.location.href = invalidUrl;
                }
            });
        }else{
            var param="param={pagenumber:"+currentpage+",pagecount:"+pagecount;
            param = getJsonDataNotEmpty(param,"phone",$("#sim-phone").val());
            param = getJsonDataNotEmpty(param,"status",$("#sim-status").val());
            param += "}";
            simData = [];
            //执行ajax获取数据然后组装
            $.ajax({
                url:serverUrl+'/simInfoManage/querySimInfoList.json',
                data:param,
                dataType:'json',
                success:function (data) {
                    suixun.hideLoding();//隐藏加载中
                    if(data.code == 200){
                        for(var i=0;i<data.info.queryresult.length;i++){
                            var obj=data.info.queryresult[i];
                            simData[i] = {id:obj.id,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                        }
                        otherData = {maxHeight:height,currentpage:currentpage,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:onPageLeft,pageRight:onPageRight,view:'SIMDelivery',batchNumber:'',upBatchNumber:''};
                        this.setState({simData:simData,otherData:otherData});
                    }
                }.bind(this),
                error: function (req,info,error) {
                    top.location.href = invalidUrl;
                }
            });
        }
    },
    //点击下拉列表
    onClickSimStatus: function (e) {
        suixun.showLoding();//显示加载中
        var elm=e.target;
        $("#sim-status").val($(elm).attr("data-status"))
        $(".election-value").html(elm.innerHTML);//赋值
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"phone",$("#sim-phone").val());
        param = getJsonDataNotEmpty(param,"status",$("#sim-status").val());
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        $.ajax({
            url:serverUrl+'/simInfoManage/querySimInfoList.json',
            data:param,
            dataType:'json',
            success:function (data) {
                suixun.hideLoding();//隐藏加载中
                if(data.code == 200){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        simData[i] = {id:obj.id,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                    }
                    var pageRight = 0;
                    if(data.info.totlepage > 1){
                        pageRight = 1
                    }
                    otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                    currentpage = 1,totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    allSimCount=data.info.totlerows;
                    this.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                    $(".drop-down").slideUp();
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });
    },
    //注销SIM卡
    onClickLogoutSIM: function () {
        var idList="";
        $(".simChildCheckBox").each(function(i,box) {
            if(box!=null && box.checked)
                idList+=$(box).attr("data-value")+"|";
        });

        if(idList.length>1){
            idList=idList.substring(0,idList.length-1);
            $("#sim_simids").val(idList);
        }else{
            suixun.alert("请先选择要注销的SIM卡");
            return false;
        }
        var svar = this;
        suixun.confirm_noTit("你确定要注销选定的SIM卡吗？",function (data) {
            if (data == true) {
                suixun.showLoding();//显示加载中
                var param = "param={";
                param = getJsonDataNotEmpty(param, "ids", idList);
                param += "}";
                $.ajax({
                    url: serverUrl + '/simInfoManage/deleteSimInfo.json',
                    data: param,
                    dataType: 'json',
                    success: function (data) {
                        suixun.hideLoding(200);//隐藏加载中
                        if (data != null && data.code != null && data.code == 200) {
                            suixun.alert("注销成功",function (data) {
                                if(data){
                                    svar.onPageClick(currentpage);
                                }
                            });
                        } else {
                            suixun.alert((data != null && data.msg != null) ? data.msg : "注销失败");
                        }
                    }.bind(this),
                    error: function (req,info,error) {
                        top.location.href = invalidUrl;
                    }
                });
            }
        });
    },
    //新增SIM卡
    onClickAddSIM: function () {
        $(".initializeMenu", window.parent.document).show();//父页面的遮罩
        $(".addSIM").show();
    },
    //批量导入
    onClickImportExport: function () {
        $(".initializeMenu", window.parent.document).show();//父页面的遮罩
        $(".excelInput").show();
    },
    //导入保存的按钮
    excelInput: function () {
        suixun.showLoding();//显示加载中
        var svar = this;
        var file_name = $(".file_name").val();
        if(file_name != ""){
            var formData=new FormData($("#excelInputFrom")[0]);
            $.ajax({
                url:serverUrl+'/simInfoManage/importSim.json',
                type:'POST',
                data:formData,
                dataType:'json',
                contentType:false,
                processData: false,
                success:function (data) {
                    suixun.hideLoding(200);//隐藏加载中
                    if(data.code == 200){
                        suixun.alert(data.info.result,function (data) {
                            if(data){
                                $(".excelInput").hide();
                                svar.onClickQueryLastSim();
//                                    svar.onPageClick(1);
                            }
                        })
                    }else{
                        suixun.alert(data.msg)
                    }
                },
                error: function (req,info,error) {
                    top.location.href = invalidUrl;
                }
            });
        }else{
            suixun.alert("请选择上传文件!");
        }
    },
    //输入手机号码搜索
    onClickQueryPhone: function () {
        suixun.showLoding();//显示加载中
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"phone",$("#sim-phone").val());
        param = getJsonDataNotEmpty(param,"status",$("#sim-status").val());
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        $.ajax({
            url:serverUrl+'/simInfoManage/querySimInfoList.json',
            data:param,
            dataType:'json',
            success:function (data) {
                suixun.hideLoding();//隐藏加载中
                if(data.code == 200){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        simData[i] = {id:obj.id,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                    }
                    var pageRight = 0;
                    if(data.info.totlerows > 1){
                        pageRight = 1
                    }
                    otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                    currentpage = 1,totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    allSimCount=data.info.totlerows;
                    this.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });
    },
    //查询最后一次入库
    onClickQueryLastSim: function () {
        suixun.showLoding();//显示加载中
        tempCurrentPage = currentpage;
        importSimData = [];
        importSim.isImportSim = true;
        this.setState({importSim:importSim});
        var param="param={";
        param = getJsonDataNotEmpty(param,"pagenumber","1");
        param = getJsonDataNotEmpty(param,"pagecount","15");
        param += "}";
        $.ajax({
            url:serverUrl+'/simInfoManage/querySimTmpList.json',
            data:param,
            dataType:'json',
            success:function (data) {
                suixun.hideLoding();//隐藏加载中
                if(data.code == 200){
                    if( data.info.queryresult != null ){
                        for(var i=0;i<data.info.queryresult.length;i++){
                            var obj=data.info.queryresult[i];
                            importSimData[i] = {id:i,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,createtimestr:obj.createtimestr};
                        }
                    }
                    otherData.totlepage = data.info.totlepage;
                    otherData.totlerows = data.info.totlerows;
                    otherData.pageLeft = 0;
                    if(data.info.totlepage > 1){
                        otherData.pageRight = 1;
                    }else{
                        otherData.pageRight = 0;
                    }
                    otherData.currentpage = 1;
                    currentpage = 1;
                    totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    this.setState({importSimData:importSimData,otherData:otherData});
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });
    },
    //返回
    onClickReturn: function () {
        $(".election-value").html("按条件筛选");
        this.props.onClickSIMDelivery();
//            this.onPageClick(tempCurrentPage);
        importSim.isImportSim = false;
        this.setState({importSim:importSim});
    },
    //撤销操作
    onClickRevoke: function () {
        suixun.showLoding();//显示加载中
        var svar = this;
        $.ajax({
            url:serverUrl+'/simInfoManage/cancelSimImport.json',
            dataType:'json',
            success:function (data) {
                suixun.hideLoding(200);//隐藏加载中
                if(data.code == 200){
                    suixun.alert(data.result,function (data) {
                        if(data){
                            svar.onClickReturn();
                        }
                    })
                }else{
                    suixun.alert(data.msg);
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });
    },
    render: function () {
        {
            var Tabels = simData.map(function (data) {
                return (
                    <SIMTable key={data.id} id={data.id} operations={data.operations}  phone={data.phone}  iccid={data.iccid}  peoplename={data.peoplename}  peopleidcard={data.peopleidcard}  mdtid={data.mdtid} status={data.status} />
                )
            })
            var importTabels = importSimData.map(function (data) {
                return (
                    <ImportSIMTable key={data.id} operations={data.operations}  phone={data.phone}  iccid={data.iccid}  createtimestr={data.createtimestr}  />
                )
            })
        }
        return (
            <div className="outside">
                <div style={{display:importSim.isImportSim == true?"none":"block"}} className="sim-rightTable">
                    <Addbatchnumber onClockSaveAddbatchnumber={this.onClockSaveAddbatchnumber} />
                    <AddSIM onPageClick={this.onPageClick}/>
                    <ExcelInput excelInput={this.excelInput} onClickQueryLastSim={this.onClickQueryLastSim}/>
                    <header >
                        <div className="header-left">
                            <div className="header-left-number" style={{float: "left",color:'#01b4ee',marginLeft:"0px"}}>
                                <span className="header-left-batchid" >{otherData.batchNumber}</span>
                            </div>
                            <div className="header-left-select" >
                                <div className="election-value">按条件筛选</div>
                                <span className="lower-right-corner" style={{left:"90px"}}/>
                                <div className="drop-down" >
                                    <span className="select-value" data-status="0" onClick={this.onClickSimStatus}>未使用</span>
                                    <span className="select-value" data-status="1" onClick={this.onClickSimStatus}>已使用</span>
                                    <span className="select-value" data-status="-1" onClick={this.onClickSimStatus}>已注销</span>
                                </div>
                            </div>
                            <div className="header-left-query">
                                <div className="header-left-query-input">
                                    <input className="queryVal" type="text" placeholder="请输入手机号搜索" style={{top:"-4px"}} name="sim-phone" id="sim-phone"/>
                                    <input type="hidden" name="sim-status" id="sim-status"/>
                                </div>
                                <div className="header-left-query-img" onClick={this.onClickQueryPhone}></div>
                            </div>
                        </div>
                        <div className="header-right ">
                            <div style={{marginRight: '0px',width:'150px'}} className="addButton" onClick={this.onClickQueryLastSim}>
                                查询最后一次入库
                            </div>
                            <div style={{marginRight: '0px'}} className="addButton" onClick={this.onClickLogoutSIM}>
                                <span className="addButton-img"><img src="../img/icon/gotOut.png" /></span>
                                <span className="addButton-text">注销</span>
                            </div>
                            <div style={{marginRight: '30px'}} className="addButton" onClick={this.onClickAddSIM}>
                                <span className="addButton-img"><img src="../img/icon/add-white.png" /></span>
                                <span className="addButton-text">新增</span>
                            </div>
                            <div className="export"   onClick={this.onClickImportExport}>
                                <span className="export-img"><img src="../img/icon/export.png" /></span>
                                <span className="export-text">批量导入</span>
                            </div>
                        </div>
                    </header>

                    <div className=" tableInfo">
                        <div className="studentsInfo-data tableInfo-data">
                            <div className="studentsInfo-data-table tableInfo-data-table" >
                                <table className="head-body ">
                                    <thead>
                                    <th style={{width: '3%'}}><input type="checkbox" className="simCheckBox"/></th>
                                    <th style={{width: '10%'}}>运营商</th>
                                    <th style={{width: '10%'}}>手机号</th>
                                    <th style={{width: '10%'}}>ICCID</th>
                                    <th style={{width: '10%'}}>激活姓名</th>
                                    <th style={{width: '10%'}}>身份证号</th>
                                    <th style={{width: '10%'}}>关联设备</th>
                                    <th style={{width: '10%'}}>状态</th>
                                    </thead>
                                    <tbody className="SIMDelivery-body">
                                    {Tabels}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <Page otherData={otherData} onPageClick={this.onPageClick} />
                    </div>
                    <footer id="copyright">
                        <span><img src="../img/icon/copyright.png"/>{copyright}</span>
                    </footer>
                </div>
                <div className="" style={{display:importSim.isImportSim==false?"none":"block"}}>
                    <header >
                        <div className="header-left">
                            <div style={{marginRight: '0px'}} className="addButton" onClick={this.onClickReturn}>
                                <span className="addButton-img"><img style={{position: "relative",top: "6px"}} src="../img/icon/fanhui.png" /></span>
                                <span className="addButton-text">返回</span>
                            </div>
                        </div>
                        <div className="header-right ">
                            <div className="addButton" style={{width:'105px'}} onClick={this.onClickRevoke}>
                                <span className="addButton-img" style={{left: "-34px"}}><img src="../img/icon/gotOut.png" /></span>
                                <span className="addButton-text" style={{width:'75px'}} >全部撤销</span>
                            </div>
                        </div>
                    </header>
                    <div className=" tableInfo">
                        <div className="studentsInfo-data tableInfo-data">
                            <div className="studentsInfo-data-table tableInfo-data-table" >
                                <table className="head-body ">
                                    <thead>
                                    <th style={{width: '25%'}}>运营商</th>
                                    <th style={{width: '25%'}}>手机号</th>
                                    <th style={{width: '25%'}}>ICCID</th>
                                    <th style={{width: '25%'}}>导入时间</th>
                                    </thead>
                                    <tbody >
                                    {importTabels}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <Page otherData={otherData} onPageClick={this.onPageClick} />
                    </div>
                    <footer id="copyright">
                        <span><img src="../../img/icon/copyright.png"/>{copyright}</span>
                    </footer>
                </div>
            </div>
        )
    },
})

//父组件
var Main = React.createClass({
    //组件初始状态
    getInitialState: function () {
        return {otherData:this.props.otherData,simData:this.props.simData,allSimCount:this.props.allSimCount,importSim:this.props.importSim,importSimData:this.props.importSimData}
    },
    componentDidMount: function () {
        this.onClickSIMDelivery();

    },
    //学校
    onClickSchool: function () {
        window.location.href = "../schoolManage/querySchoolList.html";
    },
    //设备投放
    onClickDeviceDelivery: function () {
        window.location.href = "../deviceInitManage/queryDeviceInitList.html";
    },
    //SIM卡投放
    onClickSIMDelivery: function () {
        otherData.view = "SIMDelivery";
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        $.ajax({
            url:serverUrl+'/simInfoManage/querySimInfoList.json',
            data:param,
            dataType:'json',
            success:function (data) {
                setTimeout(function () {
                    suixun.hideLoding();//隐藏加载中
                },500);
                if(data.code == 200){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        simData[i] = {id:obj.id,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                    }
                    var pageRight = 0;
                    if(data.info.totlepage > 1){
                        pageRight = 1;
                    }
                    otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                    currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    allSimCount=data.info.totlerows;
                    this.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                }
            }.bind(this),
            error: function (req,info,error) {
                top.location.href = invalidUrl;
            }
        });

    },
    //设备套餐
    onClickDeviceSetMeal: function () {
        window.location.href = "../packageManage/queryPackageList.html";
    },
    //设备零售价
    onClickDeviceRetailPrice: function () {
        window.location.href = "../devicePriceManage/queryDevicePriceList.html";
    },
    //下载Excel模版
    excleModel: function () {
        window.location.href = serverUrl+"/simInfoManage/export_simTamplate.json";
    },
    render: function () {
        return (
            <div className="outside" >
                <div className="header-menu">
                    <ul>
                        <li onClick={this.onClickSchool} >学校</li>
                        <li onClick={this.onClickDeviceDelivery} >设备管理</li>
                        <li onClick={this.onClickSIMDelivery} className="select" >SIM卡管理</li>
                        <li onClick={this.onClickDeviceSetMeal} style={{display:"none"}}>设备套餐</li>
                        <li onClick={this.onClickDeviceRetailPrice} style={{display:"none"}}>设备零售价</li>
                    </ul>
                    <div onClick={this.excleModel} className="excleModel" >
                        <img src="../img/icon/annotations.png" />
                        <span>导出Excel模版下载</span>
                    </div>
                </div>
                <div className="SIMDelivery tableManage-body">
                    <SIMDelivery onClickSIMDelivery={this.onClickSIMDelivery}/>
                </div>
            </div>
        );
    }
});
ReactDOM.render(
    <Main  otherData={otherData} simData={simData}  allSimCount={allSimCount} importSim={importSim} importSimData={importSimData} />,
    document.getElementById('tableManage')
);

//点击下拉框
$(".header-left-select").click(function () {
    var dropDown = $(this).find('.drop-down');
    if(dropDown.is(":hidden")){
        dropDown.slideDown();
    }else{
        dropDown.slideUp();
    }
});
//鼠标移动函数 —— 下拉选择学校、姓名
$('.header-left .election-value,.header-right .election-value').hover(function(){
        if($(".drop-down").is(":hidden")){
            $(this).parent().find('.drop-down').slideDown();
            $(this).parent().hover(function(){},
                function(){
                    $(this).parent().find(".drop-down").slideUp();
                }
            );
        }
    },function(){}
);
//设置main页面右边的最小宽度
/*$('.main-right', window.parent.document).css("minWidth","1274px");*/
$(".parentCheckBox").click(function(){
    if($(".parentCheckBox").is(":checked")){
        $(".childrenCheckBox").prop("checked",true);
    }else{
        $(".childrenCheckBox").attr("checked",false);
    }
});
//sim卡管理
$(".simCheckBox").click(function(){
    if($(".simCheckBox").is(":checked")){
        $(".simChildCheckBox").prop("checked",true);
    }else{
        $(".simChildCheckBox").attr("checked",false);
    }
});
